package avicit.bdp.oss.utils.stats;

import avicit.bdp.oss.utils.common.Constants;
import avicit.bdp.oss.utils.common.TimeUtils;

/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2020-11-12
 * @类说明：StorageStats
 * @修改记录：
 * @注意事项：
 * @主要功能：存量统计信息，包括指定bucket存储容量、对象总量、最近七天存储容量/对象总量统计信息
 */
public class BucketStorageStats {
    /**
     * 存储总量，单位是B
     */
    private long tatalCapacity;

    /**
     * 对象数量总量，单位是个
     */
    private long totalObjectNum;

    /**
     * 近七天存储容量统计信息;默认最后一个是今日统计值
     */
    Para[] recentCapacity;

    /**
     * 近七天对象数量统计信息;默认最后一个是今日统计值
     */
    Para[] recentObjectNum;

    /**
     * 无参构造函数，注意对近七天统计信息初始化
     */
    public BucketStorageStats() {
        totalObjectNum = 0L;
        totalObjectNum = 0L;
        recentCapacity = new Para[Constants.RECENT_DAYS];
        recentObjectNum = new Para[Constants.RECENT_DAYS];

        // 当前时间
        long currTime = System.currentTimeMillis();
        // 当天开始时间
        long currDayStartTime = TimeUtils.getDailyStartTime(currTime, Constants.TIME_ZONE);

        int cnt = Constants.RECENT_DAYS - 1;
        for (int i = 0; i < Constants.RECENT_DAYS; i++) {
            Para capacityPara = new Para();
            Para objectNumPara = new Para();
            recentCapacity[i] = capacityPara;
            recentObjectNum[i] = objectNumPara;

            capacityPara.setStamp(currDayStartTime + Constants.DAY_MILLS * cnt);
            objectNumPara.setStamp(currDayStartTime);
            capacityPara.setValue(0L);
            objectNumPara.setValue(0L);

            cnt--;
        }
    }

    public long getTatalCapacity() {
        return tatalCapacity;
    }

    public long getTotalObjectNum() {
        return totalObjectNum;
    }

    public Para[] getRecentCapacity() {
        return recentCapacity;
    }

    public Para[] getRecentObjectNum() {
        return recentObjectNum;
    }

    public void setTatalCapacity(long tatalCapacity) {
        this.tatalCapacity = tatalCapacity;
    }

    public void setTotalObjectNum(long totalObjectNum) {
        this.totalObjectNum = totalObjectNum;
    }

    public void setRecentCapacity(Para[] recentCapacity) {
        this.recentCapacity = recentCapacity;
    }

    public void setRecentObjectNum(Para[] recentObjectNum) {
        this.recentObjectNum = recentObjectNum;
    }

    /**
     * 参数信息，存储容量或对象数量
     */
    public static class Para {
        /**
         * 时间戳
         */
        private long stamp;

        /**
         * 参数值
         */
        private long value;

        public long getStamp() {
            return stamp;
        }

        public long getValue() {
            return value;
        }

        public void setStamp(long stamp) {
            this.stamp = stamp;
        }

        public void setValue(long value) {
            this.value = value;
        }
    }
}
